package com.situ.mall.admin.controller;

import com.ramostear.captcha.HappyCaptcha;
import com.situ.mall.admin.service.IAdministratorService;
import com.situ.mall.admin.service.IStatisticsService;
import com.situ.mall.admin.util.RequestUtil;
import com.situ.mall.base.util.URLUtil;
import com.situ.mall.base.vo.ResVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;


/**
 * ClassName: LogController
 * Package: com.situ.mall.controller
 * Description:
 *
 * @Author Darling_达
 * @Create 2023-03-17 14:46
 * @Version 1.0
 */

@Controller
@RequestMapping("/")
public class LogController {

    @Autowired
    private IAdministratorService administratorService;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;


    @GetMapping(URLUtil.INDEX)
    public String index() {
        return URLUtil.INDEX_HTML;
    }

    @GetMapping(URLUtil.LOGIN)
    public String login() {
        return URLUtil.LOGIN_HTML;
    }

    @PostMapping(URLUtil.LOGIN)
    @ResponseBody
    public ResVO check(String username, String password) {
        boolean b = administratorService.check(username, password);
        ResVO vo = new ResVO();
        if (b) {
           vo.setCode(1);
        }
        return vo;
    }


    @GetMapping(URLUtil.LOGOUT)
    public String logout() {
        RequestUtil.removeAttribute();
        return URLUtil.REDIRECT + URLUtil.LOGOUT;
    }


}
